/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package vn.com.fis.portal.service.persistence;

import com.liferay.portal.NoSuchModelException;
import com.liferay.portal.kernel.bean.BeanReference;
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.InstanceFactory;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.service.persistence.BatchSessionUtil;
import com.liferay.portal.service.persistence.ResourcePersistence;
import com.liferay.portal.service.persistence.UserPersistence;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;

import vn.com.fis.portal.NoSuchVideoUserEntryException;
import vn.com.fis.portal.model.VideoUserEntry;
import vn.com.fis.portal.model.impl.VideoUserEntryImpl;
import vn.com.fis.portal.model.impl.VideoUserEntryModelImpl;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * The persistence implementation for the video user entry service.
 *
 * <p>
 * Caching information and settings can be found in <code>portal.properties</code>
 * </p>
 *
 * @author loind
 * @see VideoUserEntryPersistence
 * @see VideoUserEntryUtil
 * @generated
 */
public class VideoUserEntryPersistenceImpl extends BasePersistenceImpl<VideoUserEntry>
	implements VideoUserEntryPersistence {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. Always use {@link VideoUserEntryUtil} to access the video user entry persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
	 */
	public static final String FINDER_CLASS_NAME_ENTITY = VideoUserEntryImpl.class.getName();
	public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List1";
	public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List2";
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USER_ORIGINCODE =
		new FinderPath(VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoUserEntryModelImpl.FINDER_CACHE_ENABLED,
			VideoUserEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
			"findByUser_OriginCode",
			new String[] {
				Long.class.getName(), Integer.class.getName(),
				
			"java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USER_ORIGINCODE =
		new FinderPath(VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoUserEntryModelImpl.FINDER_CACHE_ENABLED,
			VideoUserEntryImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUser_OriginCode",
			new String[] { Long.class.getName(), Integer.class.getName() },
			VideoUserEntryModelImpl.USERID_COLUMN_BITMASK |
			VideoUserEntryModelImpl.ORIGINCODE_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_USER_ORIGINCODE = new FinderPath(VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoUserEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"countByUser_OriginCode",
			new String[] { Long.class.getName(), Integer.class.getName() });
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USER_SERVICEACTIVE =
		new FinderPath(VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoUserEntryModelImpl.FINDER_CACHE_ENABLED,
			VideoUserEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
			"findByUser_ServiceActive",
			new String[] {
				Long.class.getName(), Integer.class.getName(),
				
			"java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USER_SERVICEACTIVE =
		new FinderPath(VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoUserEntryModelImpl.FINDER_CACHE_ENABLED,
			VideoUserEntryImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"findByUser_ServiceActive",
			new String[] { Long.class.getName(), Integer.class.getName() },
			VideoUserEntryModelImpl.USERID_COLUMN_BITMASK |
			VideoUserEntryModelImpl.SERVICEACTIVE_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_USER_SERVICEACTIVE = new FinderPath(VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoUserEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"countByUser_ServiceActive",
			new String[] { Long.class.getName(), Integer.class.getName() });
	public static final FinderPath FINDER_PATH_FETCH_BY_VIDEOID_USERID = new FinderPath(VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoUserEntryModelImpl.FINDER_CACHE_ENABLED,
			VideoUserEntryImpl.class, FINDER_CLASS_NAME_ENTITY,
			"fetchByVideoId_UserId",
			new String[] { Long.class.getName(), Long.class.getName() },
			VideoUserEntryModelImpl.VIDEOID_COLUMN_BITMASK |
			VideoUserEntryModelImpl.USERID_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_VIDEOID_USERID = new FinderPath(VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoUserEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByVideoId_UserId",
			new String[] { Long.class.getName(), Long.class.getName() });
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ORIGINCODE_SERVICEACTIVE =
		new FinderPath(VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoUserEntryModelImpl.FINDER_CACHE_ENABLED,
			VideoUserEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
			"findByOriginCode_ServiceActive",
			new String[] {
				Integer.class.getName(), Integer.class.getName(),
				
			"java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORIGINCODE_SERVICEACTIVE =
		new FinderPath(VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoUserEntryModelImpl.FINDER_CACHE_ENABLED,
			VideoUserEntryImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"findByOriginCode_ServiceActive",
			new String[] { Integer.class.getName(), Integer.class.getName() },
			VideoUserEntryModelImpl.ORIGINCODE_COLUMN_BITMASK |
			VideoUserEntryModelImpl.SERVICEACTIVE_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_ORIGINCODE_SERVICEACTIVE =
		new FinderPath(VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoUserEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"countByOriginCode_ServiceActive",
			new String[] { Integer.class.getName(), Integer.class.getName() });
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoUserEntryModelImpl.FINDER_CACHE_ENABLED,
			VideoUserEntryImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoUserEntryModelImpl.FINDER_CACHE_ENABLED,
			VideoUserEntryImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
			"findAll", new String[0]);
	public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoUserEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);

	/**
	 * Caches the video user entry in the entity cache if it is enabled.
	 *
	 * @param videoUserEntry the video user entry
	 */
	public void cacheResult(VideoUserEntry videoUserEntry) {
		EntityCacheUtil.putResult(VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoUserEntryImpl.class, videoUserEntry.getPrimaryKey(),
			videoUserEntry);

		FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIDEOID_USERID,
			new Object[] {
				Long.valueOf(videoUserEntry.getVideoId()),
				Long.valueOf(videoUserEntry.getUserId())
			}, videoUserEntry);

		videoUserEntry.resetOriginalValues();
	}

	/**
	 * Caches the video user entries in the entity cache if it is enabled.
	 *
	 * @param videoUserEntries the video user entries
	 */
	public void cacheResult(List<VideoUserEntry> videoUserEntries) {
		for (VideoUserEntry videoUserEntry : videoUserEntries) {
			if (EntityCacheUtil.getResult(
						VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
						VideoUserEntryImpl.class, videoUserEntry.getPrimaryKey()) == null) {
				cacheResult(videoUserEntry);
			}
			else {
				videoUserEntry.resetOriginalValues();
			}
		}
	}

	/**
	 * Clears the cache for all video user entries.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache() {
		if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
			CacheRegistryUtil.clear(VideoUserEntryImpl.class.getName());
		}

		EntityCacheUtil.clearCache(VideoUserEntryImpl.class.getName());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	/**
	 * Clears the cache for the video user entry.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache(VideoUserEntry videoUserEntry) {
		EntityCacheUtil.removeResult(VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoUserEntryImpl.class, videoUserEntry.getPrimaryKey());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

		clearUniqueFindersCache(videoUserEntry);
	}

	@Override
	public void clearCache(List<VideoUserEntry> videoUserEntries) {
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

		for (VideoUserEntry videoUserEntry : videoUserEntries) {
			EntityCacheUtil.removeResult(VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
				VideoUserEntryImpl.class, videoUserEntry.getPrimaryKey());

			clearUniqueFindersCache(videoUserEntry);
		}
	}

	protected void clearUniqueFindersCache(VideoUserEntry videoUserEntry) {
		FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VIDEOID_USERID,
			new Object[] {
				Long.valueOf(videoUserEntry.getVideoId()),
				Long.valueOf(videoUserEntry.getUserId())
			});
	}

	/**
	 * Creates a new video user entry with the primary key. Does not add the video user entry to the database.
	 *
	 * @param videoUserId the primary key for the new video user entry
	 * @return the new video user entry
	 */
	public VideoUserEntry create(long videoUserId) {
		VideoUserEntry videoUserEntry = new VideoUserEntryImpl();

		videoUserEntry.setNew(true);
		videoUserEntry.setPrimaryKey(videoUserId);

		return videoUserEntry;
	}

	/**
	 * Removes the video user entry with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param videoUserId the primary key of the video user entry
	 * @return the video user entry that was removed
	 * @throws vn.com.fis.portal.NoSuchVideoUserEntryException if a video user entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoUserEntry remove(long videoUserId)
		throws NoSuchVideoUserEntryException, SystemException {
		return remove(Long.valueOf(videoUserId));
	}

	/**
	 * Removes the video user entry with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param primaryKey the primary key of the video user entry
	 * @return the video user entry that was removed
	 * @throws vn.com.fis.portal.NoSuchVideoUserEntryException if a video user entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public VideoUserEntry remove(Serializable primaryKey)
		throws NoSuchVideoUserEntryException, SystemException {
		Session session = null;

		try {
			session = openSession();

			VideoUserEntry videoUserEntry = (VideoUserEntry)session.get(VideoUserEntryImpl.class,
					primaryKey);

			if (videoUserEntry == null) {
				if (_log.isWarnEnabled()) {
					_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
				}

				throw new NoSuchVideoUserEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
					primaryKey);
			}

			return remove(videoUserEntry);
		}
		catch (NoSuchVideoUserEntryException nsee) {
			throw nsee;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	@Override
	protected VideoUserEntry removeImpl(VideoUserEntry videoUserEntry)
		throws SystemException {
		videoUserEntry = toUnwrappedModel(videoUserEntry);

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.delete(session, videoUserEntry);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		clearCache(videoUserEntry);

		return videoUserEntry;
	}

	@Override
	public VideoUserEntry updateImpl(
		vn.com.fis.portal.model.VideoUserEntry videoUserEntry, boolean merge)
		throws SystemException {
		videoUserEntry = toUnwrappedModel(videoUserEntry);

		boolean isNew = videoUserEntry.isNew();

		VideoUserEntryModelImpl videoUserEntryModelImpl = (VideoUserEntryModelImpl)videoUserEntry;

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.update(session, videoUserEntry, merge);

			videoUserEntry.setNew(false);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

		if (isNew || !VideoUserEntryModelImpl.COLUMN_BITMASK_ENABLED) {
			FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
		}

		else {
			if ((videoUserEntryModelImpl.getColumnBitmask() &
					FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USER_ORIGINCODE.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						Long.valueOf(videoUserEntryModelImpl.getOriginalUserId()),
						Integer.valueOf(videoUserEntryModelImpl.getOriginalOriginCode())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USER_ORIGINCODE,
					args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USER_ORIGINCODE,
					args);

				args = new Object[] {
						Long.valueOf(videoUserEntryModelImpl.getUserId()),
						Integer.valueOf(videoUserEntryModelImpl.getOriginCode())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USER_ORIGINCODE,
					args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USER_ORIGINCODE,
					args);
			}

			if ((videoUserEntryModelImpl.getColumnBitmask() &
					FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USER_SERVICEACTIVE.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						Long.valueOf(videoUserEntryModelImpl.getOriginalUserId()),
						Integer.valueOf(videoUserEntryModelImpl.getOriginalServiceActive())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USER_SERVICEACTIVE,
					args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USER_SERVICEACTIVE,
					args);

				args = new Object[] {
						Long.valueOf(videoUserEntryModelImpl.getUserId()),
						Integer.valueOf(videoUserEntryModelImpl.getServiceActive())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USER_SERVICEACTIVE,
					args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USER_SERVICEACTIVE,
					args);
			}

			if ((videoUserEntryModelImpl.getColumnBitmask() &
					FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORIGINCODE_SERVICEACTIVE.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						Integer.valueOf(videoUserEntryModelImpl.getOriginalOriginCode()),
						Integer.valueOf(videoUserEntryModelImpl.getOriginalServiceActive())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ORIGINCODE_SERVICEACTIVE,
					args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORIGINCODE_SERVICEACTIVE,
					args);

				args = new Object[] {
						Integer.valueOf(videoUserEntryModelImpl.getOriginCode()),
						Integer.valueOf(videoUserEntryModelImpl.getServiceActive())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ORIGINCODE_SERVICEACTIVE,
					args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORIGINCODE_SERVICEACTIVE,
					args);
			}
		}

		EntityCacheUtil.putResult(VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
			VideoUserEntryImpl.class, videoUserEntry.getPrimaryKey(),
			videoUserEntry);

		if (isNew) {
			FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIDEOID_USERID,
				new Object[] {
					Long.valueOf(videoUserEntry.getVideoId()),
					Long.valueOf(videoUserEntry.getUserId())
				}, videoUserEntry);
		}
		else {
			if ((videoUserEntryModelImpl.getColumnBitmask() &
					FINDER_PATH_FETCH_BY_VIDEOID_USERID.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						Long.valueOf(videoUserEntryModelImpl.getOriginalVideoId()),
						Long.valueOf(videoUserEntryModelImpl.getOriginalUserId())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_VIDEOID_USERID,
					args);
				FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VIDEOID_USERID,
					args);

				FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIDEOID_USERID,
					new Object[] {
						Long.valueOf(videoUserEntry.getVideoId()),
						Long.valueOf(videoUserEntry.getUserId())
					}, videoUserEntry);
			}
		}

		return videoUserEntry;
	}

	protected VideoUserEntry toUnwrappedModel(VideoUserEntry videoUserEntry) {
		if (videoUserEntry instanceof VideoUserEntryImpl) {
			return videoUserEntry;
		}

		VideoUserEntryImpl videoUserEntryImpl = new VideoUserEntryImpl();

		videoUserEntryImpl.setNew(videoUserEntry.isNew());
		videoUserEntryImpl.setPrimaryKey(videoUserEntry.getPrimaryKey());

		videoUserEntryImpl.setVideoUserId(videoUserEntry.getVideoUserId());
		videoUserEntryImpl.setVideoId(videoUserEntry.getVideoId());
		videoUserEntryImpl.setUserId(videoUserEntry.getUserId());
		videoUserEntryImpl.setOriginCode(videoUserEntry.getOriginCode());
		videoUserEntryImpl.setDate_(videoUserEntry.getDate_());
		videoUserEntryImpl.setStartDate(videoUserEntry.getStartDate());
		videoUserEntryImpl.setEndDate(videoUserEntry.getEndDate());
		videoUserEntryImpl.setSenderId(videoUserEntry.getSenderId());
		videoUserEntryImpl.setServiceActive(videoUserEntry.getServiceActive());
		videoUserEntryImpl.setStatus(videoUserEntry.getStatus());

		return videoUserEntryImpl;
	}

	/**
	 * Returns the video user entry with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
	 *
	 * @param primaryKey the primary key of the video user entry
	 * @return the video user entry
	 * @throws com.liferay.portal.NoSuchModelException if a video user entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public VideoUserEntry findByPrimaryKey(Serializable primaryKey)
		throws NoSuchModelException, SystemException {
		return findByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the video user entry with the primary key or throws a {@link vn.com.fis.portal.NoSuchVideoUserEntryException} if it could not be found.
	 *
	 * @param videoUserId the primary key of the video user entry
	 * @return the video user entry
	 * @throws vn.com.fis.portal.NoSuchVideoUserEntryException if a video user entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoUserEntry findByPrimaryKey(long videoUserId)
		throws NoSuchVideoUserEntryException, SystemException {
		VideoUserEntry videoUserEntry = fetchByPrimaryKey(videoUserId);

		if (videoUserEntry == null) {
			if (_log.isWarnEnabled()) {
				_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + videoUserId);
			}

			throw new NoSuchVideoUserEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
				videoUserId);
		}

		return videoUserEntry;
	}

	/**
	 * Returns the video user entry with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param primaryKey the primary key of the video user entry
	 * @return the video user entry, or <code>null</code> if a video user entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public VideoUserEntry fetchByPrimaryKey(Serializable primaryKey)
		throws SystemException {
		return fetchByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the video user entry with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param videoUserId the primary key of the video user entry
	 * @return the video user entry, or <code>null</code> if a video user entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoUserEntry fetchByPrimaryKey(long videoUserId)
		throws SystemException {
		VideoUserEntry videoUserEntry = (VideoUserEntry)EntityCacheUtil.getResult(VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
				VideoUserEntryImpl.class, videoUserId);

		if (videoUserEntry == _nullVideoUserEntry) {
			return null;
		}

		if (videoUserEntry == null) {
			Session session = null;

			boolean hasException = false;

			try {
				session = openSession();

				videoUserEntry = (VideoUserEntry)session.get(VideoUserEntryImpl.class,
						Long.valueOf(videoUserId));
			}
			catch (Exception e) {
				hasException = true;

				throw processException(e);
			}
			finally {
				if (videoUserEntry != null) {
					cacheResult(videoUserEntry);
				}
				else if (!hasException) {
					EntityCacheUtil.putResult(VideoUserEntryModelImpl.ENTITY_CACHE_ENABLED,
						VideoUserEntryImpl.class, videoUserId,
						_nullVideoUserEntry);
				}

				closeSession(session);
			}
		}

		return videoUserEntry;
	}

	/**
	 * Returns all the video user entries where userId = &#63; and originCode = &#63;.
	 *
	 * @param userId the user ID
	 * @param originCode the origin code
	 * @return the matching video user entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoUserEntry> findByUser_OriginCode(long userId,
		int originCode) throws SystemException {
		return findByUser_OriginCode(userId, originCode, QueryUtil.ALL_POS,
			QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the video user entries where userId = &#63; and originCode = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param userId the user ID
	 * @param originCode the origin code
	 * @param start the lower bound of the range of video user entries
	 * @param end the upper bound of the range of video user entries (not inclusive)
	 * @return the range of matching video user entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoUserEntry> findByUser_OriginCode(long userId,
		int originCode, int start, int end) throws SystemException {
		return findByUser_OriginCode(userId, originCode, start, end, null);
	}

	/**
	 * Returns an ordered range of all the video user entries where userId = &#63; and originCode = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param userId the user ID
	 * @param originCode the origin code
	 * @param start the lower bound of the range of video user entries
	 * @param end the upper bound of the range of video user entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of matching video user entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoUserEntry> findByUser_OriginCode(long userId,
		int originCode, int start, int end, OrderByComparator orderByComparator)
		throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = null;

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USER_ORIGINCODE;
			finderArgs = new Object[] { userId, originCode };
		}
		else {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USER_ORIGINCODE;
			finderArgs = new Object[] {
					userId, originCode,
					
					start, end, orderByComparator
				};
		}

		List<VideoUserEntry> list = (List<VideoUserEntry>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;

			if (orderByComparator != null) {
				query = new StringBundler(4 +
						(orderByComparator.getOrderByFields().length * 3));
			}
			else {
				query = new StringBundler(4);
			}

			query.append(_SQL_SELECT_VIDEOUSERENTRY_WHERE);

			query.append(_FINDER_COLUMN_USER_ORIGINCODE_USERID_2);

			query.append(_FINDER_COLUMN_USER_ORIGINCODE_ORIGINCODE_2);

			if (orderByComparator != null) {
				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);
			}

			else {
				query.append(VideoUserEntryModelImpl.ORDER_BY_JPQL);
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(userId);

				qPos.add(originCode);

				list = (List<VideoUserEntry>)QueryUtil.list(q, getDialect(),
						start, end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Returns the first video user entry in the ordered set where userId = &#63; and originCode = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param userId the user ID
	 * @param originCode the origin code
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the first matching video user entry
	 * @throws vn.com.fis.portal.NoSuchVideoUserEntryException if a matching video user entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoUserEntry findByUser_OriginCode_First(long userId,
		int originCode, OrderByComparator orderByComparator)
		throws NoSuchVideoUserEntryException, SystemException {
		List<VideoUserEntry> list = findByUser_OriginCode(userId, originCode,
				0, 1, orderByComparator);

		if (list.isEmpty()) {
			StringBundler msg = new StringBundler(6);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("userId=");
			msg.append(userId);

			msg.append(", originCode=");
			msg.append(originCode);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			throw new NoSuchVideoUserEntryException(msg.toString());
		}
		else {
			return list.get(0);
		}
	}

	/**
	 * Returns the last video user entry in the ordered set where userId = &#63; and originCode = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param userId the user ID
	 * @param originCode the origin code
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the last matching video user entry
	 * @throws vn.com.fis.portal.NoSuchVideoUserEntryException if a matching video user entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoUserEntry findByUser_OriginCode_Last(long userId,
		int originCode, OrderByComparator orderByComparator)
		throws NoSuchVideoUserEntryException, SystemException {
		int count = countByUser_OriginCode(userId, originCode);

		List<VideoUserEntry> list = findByUser_OriginCode(userId, originCode,
				count - 1, count, orderByComparator);

		if (list.isEmpty()) {
			StringBundler msg = new StringBundler(6);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("userId=");
			msg.append(userId);

			msg.append(", originCode=");
			msg.append(originCode);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			throw new NoSuchVideoUserEntryException(msg.toString());
		}
		else {
			return list.get(0);
		}
	}

	/**
	 * Returns the video user entries before and after the current video user entry in the ordered set where userId = &#63; and originCode = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param videoUserId the primary key of the current video user entry
	 * @param userId the user ID
	 * @param originCode the origin code
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the previous, current, and next video user entry
	 * @throws vn.com.fis.portal.NoSuchVideoUserEntryException if a video user entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoUserEntry[] findByUser_OriginCode_PrevAndNext(
		long videoUserId, long userId, int originCode,
		OrderByComparator orderByComparator)
		throws NoSuchVideoUserEntryException, SystemException {
		VideoUserEntry videoUserEntry = findByPrimaryKey(videoUserId);

		Session session = null;

		try {
			session = openSession();

			VideoUserEntry[] array = new VideoUserEntryImpl[3];

			array[0] = getByUser_OriginCode_PrevAndNext(session,
					videoUserEntry, userId, originCode, orderByComparator, true);

			array[1] = videoUserEntry;

			array[2] = getByUser_OriginCode_PrevAndNext(session,
					videoUserEntry, userId, originCode, orderByComparator, false);

			return array;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	protected VideoUserEntry getByUser_OriginCode_PrevAndNext(Session session,
		VideoUserEntry videoUserEntry, long userId, int originCode,
		OrderByComparator orderByComparator, boolean previous) {
		StringBundler query = null;

		if (orderByComparator != null) {
			query = new StringBundler(6 +
					(orderByComparator.getOrderByFields().length * 6));
		}
		else {
			query = new StringBundler(3);
		}

		query.append(_SQL_SELECT_VIDEOUSERENTRY_WHERE);

		query.append(_FINDER_COLUMN_USER_ORIGINCODE_USERID_2);

		query.append(_FINDER_COLUMN_USER_ORIGINCODE_ORIGINCODE_2);

		if (orderByComparator != null) {
			String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

			if (orderByConditionFields.length > 0) {
				query.append(WHERE_AND);
			}

			for (int i = 0; i < orderByConditionFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByConditionFields[i]);

				if ((i + 1) < orderByConditionFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN_HAS_NEXT);
					}
					else {
						query.append(WHERE_LESSER_THAN_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN);
					}
					else {
						query.append(WHERE_LESSER_THAN);
					}
				}
			}

			query.append(ORDER_BY_CLAUSE);

			String[] orderByFields = orderByComparator.getOrderByFields();

			for (int i = 0; i < orderByFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByFields[i]);

				if ((i + 1) < orderByFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC_HAS_NEXT);
					}
					else {
						query.append(ORDER_BY_DESC_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC);
					}
					else {
						query.append(ORDER_BY_DESC);
					}
				}
			}
		}

		else {
			query.append(VideoUserEntryModelImpl.ORDER_BY_JPQL);
		}

		String sql = query.toString();

		Query q = session.createQuery(sql);

		q.setFirstResult(0);
		q.setMaxResults(2);

		QueryPos qPos = QueryPos.getInstance(q);

		qPos.add(userId);

		qPos.add(originCode);

		if (orderByComparator != null) {
			Object[] values = orderByComparator.getOrderByConditionValues(videoUserEntry);

			for (Object value : values) {
				qPos.add(value);
			}
		}

		List<VideoUserEntry> list = q.list();

		if (list.size() == 2) {
			return list.get(1);
		}
		else {
			return null;
		}
	}

	/**
	 * Returns all the video user entries where userId = &#63; and serviceActive = &#63;.
	 *
	 * @param userId the user ID
	 * @param serviceActive the service active
	 * @return the matching video user entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoUserEntry> findByUser_ServiceActive(long userId,
		int serviceActive) throws SystemException {
		return findByUser_ServiceActive(userId, serviceActive,
			QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the video user entries where userId = &#63; and serviceActive = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param userId the user ID
	 * @param serviceActive the service active
	 * @param start the lower bound of the range of video user entries
	 * @param end the upper bound of the range of video user entries (not inclusive)
	 * @return the range of matching video user entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoUserEntry> findByUser_ServiceActive(long userId,
		int serviceActive, int start, int end) throws SystemException {
		return findByUser_ServiceActive(userId, serviceActive, start, end, null);
	}

	/**
	 * Returns an ordered range of all the video user entries where userId = &#63; and serviceActive = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param userId the user ID
	 * @param serviceActive the service active
	 * @param start the lower bound of the range of video user entries
	 * @param end the upper bound of the range of video user entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of matching video user entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoUserEntry> findByUser_ServiceActive(long userId,
		int serviceActive, int start, int end,
		OrderByComparator orderByComparator) throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = null;

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USER_SERVICEACTIVE;
			finderArgs = new Object[] { userId, serviceActive };
		}
		else {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USER_SERVICEACTIVE;
			finderArgs = new Object[] {
					userId, serviceActive,
					
					start, end, orderByComparator
				};
		}

		List<VideoUserEntry> list = (List<VideoUserEntry>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;

			if (orderByComparator != null) {
				query = new StringBundler(4 +
						(orderByComparator.getOrderByFields().length * 3));
			}
			else {
				query = new StringBundler(4);
			}

			query.append(_SQL_SELECT_VIDEOUSERENTRY_WHERE);

			query.append(_FINDER_COLUMN_USER_SERVICEACTIVE_USERID_2);

			query.append(_FINDER_COLUMN_USER_SERVICEACTIVE_SERVICEACTIVE_2);

			if (orderByComparator != null) {
				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);
			}

			else {
				query.append(VideoUserEntryModelImpl.ORDER_BY_JPQL);
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(userId);

				qPos.add(serviceActive);

				list = (List<VideoUserEntry>)QueryUtil.list(q, getDialect(),
						start, end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Returns the first video user entry in the ordered set where userId = &#63; and serviceActive = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param userId the user ID
	 * @param serviceActive the service active
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the first matching video user entry
	 * @throws vn.com.fis.portal.NoSuchVideoUserEntryException if a matching video user entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoUserEntry findByUser_ServiceActive_First(long userId,
		int serviceActive, OrderByComparator orderByComparator)
		throws NoSuchVideoUserEntryException, SystemException {
		List<VideoUserEntry> list = findByUser_ServiceActive(userId,
				serviceActive, 0, 1, orderByComparator);

		if (list.isEmpty()) {
			StringBundler msg = new StringBundler(6);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("userId=");
			msg.append(userId);

			msg.append(", serviceActive=");
			msg.append(serviceActive);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			throw new NoSuchVideoUserEntryException(msg.toString());
		}
		else {
			return list.get(0);
		}
	}

	/**
	 * Returns the last video user entry in the ordered set where userId = &#63; and serviceActive = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param userId the user ID
	 * @param serviceActive the service active
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the last matching video user entry
	 * @throws vn.com.fis.portal.NoSuchVideoUserEntryException if a matching video user entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoUserEntry findByUser_ServiceActive_Last(long userId,
		int serviceActive, OrderByComparator orderByComparator)
		throws NoSuchVideoUserEntryException, SystemException {
		int count = countByUser_ServiceActive(userId, serviceActive);

		List<VideoUserEntry> list = findByUser_ServiceActive(userId,
				serviceActive, count - 1, count, orderByComparator);

		if (list.isEmpty()) {
			StringBundler msg = new StringBundler(6);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("userId=");
			msg.append(userId);

			msg.append(", serviceActive=");
			msg.append(serviceActive);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			throw new NoSuchVideoUserEntryException(msg.toString());
		}
		else {
			return list.get(0);
		}
	}

	/**
	 * Returns the video user entries before and after the current video user entry in the ordered set where userId = &#63; and serviceActive = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param videoUserId the primary key of the current video user entry
	 * @param userId the user ID
	 * @param serviceActive the service active
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the previous, current, and next video user entry
	 * @throws vn.com.fis.portal.NoSuchVideoUserEntryException if a video user entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoUserEntry[] findByUser_ServiceActive_PrevAndNext(
		long videoUserId, long userId, int serviceActive,
		OrderByComparator orderByComparator)
		throws NoSuchVideoUserEntryException, SystemException {
		VideoUserEntry videoUserEntry = findByPrimaryKey(videoUserId);

		Session session = null;

		try {
			session = openSession();

			VideoUserEntry[] array = new VideoUserEntryImpl[3];

			array[0] = getByUser_ServiceActive_PrevAndNext(session,
					videoUserEntry, userId, serviceActive, orderByComparator,
					true);

			array[1] = videoUserEntry;

			array[2] = getByUser_ServiceActive_PrevAndNext(session,
					videoUserEntry, userId, serviceActive, orderByComparator,
					false);

			return array;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	protected VideoUserEntry getByUser_ServiceActive_PrevAndNext(
		Session session, VideoUserEntry videoUserEntry, long userId,
		int serviceActive, OrderByComparator orderByComparator, boolean previous) {
		StringBundler query = null;

		if (orderByComparator != null) {
			query = new StringBundler(6 +
					(orderByComparator.getOrderByFields().length * 6));
		}
		else {
			query = new StringBundler(3);
		}

		query.append(_SQL_SELECT_VIDEOUSERENTRY_WHERE);

		query.append(_FINDER_COLUMN_USER_SERVICEACTIVE_USERID_2);

		query.append(_FINDER_COLUMN_USER_SERVICEACTIVE_SERVICEACTIVE_2);

		if (orderByComparator != null) {
			String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

			if (orderByConditionFields.length > 0) {
				query.append(WHERE_AND);
			}

			for (int i = 0; i < orderByConditionFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByConditionFields[i]);

				if ((i + 1) < orderByConditionFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN_HAS_NEXT);
					}
					else {
						query.append(WHERE_LESSER_THAN_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN);
					}
					else {
						query.append(WHERE_LESSER_THAN);
					}
				}
			}

			query.append(ORDER_BY_CLAUSE);

			String[] orderByFields = orderByComparator.getOrderByFields();

			for (int i = 0; i < orderByFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByFields[i]);

				if ((i + 1) < orderByFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC_HAS_NEXT);
					}
					else {
						query.append(ORDER_BY_DESC_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC);
					}
					else {
						query.append(ORDER_BY_DESC);
					}
				}
			}
		}

		else {
			query.append(VideoUserEntryModelImpl.ORDER_BY_JPQL);
		}

		String sql = query.toString();

		Query q = session.createQuery(sql);

		q.setFirstResult(0);
		q.setMaxResults(2);

		QueryPos qPos = QueryPos.getInstance(q);

		qPos.add(userId);

		qPos.add(serviceActive);

		if (orderByComparator != null) {
			Object[] values = orderByComparator.getOrderByConditionValues(videoUserEntry);

			for (Object value : values) {
				qPos.add(value);
			}
		}

		List<VideoUserEntry> list = q.list();

		if (list.size() == 2) {
			return list.get(1);
		}
		else {
			return null;
		}
	}

	/**
	 * Returns the video user entry where videoId = &#63; and userId = &#63; or throws a {@link vn.com.fis.portal.NoSuchVideoUserEntryException} if it could not be found.
	 *
	 * @param videoId the video ID
	 * @param userId the user ID
	 * @return the matching video user entry
	 * @throws vn.com.fis.portal.NoSuchVideoUserEntryException if a matching video user entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoUserEntry findByVideoId_UserId(long videoId, long userId)
		throws NoSuchVideoUserEntryException, SystemException {
		VideoUserEntry videoUserEntry = fetchByVideoId_UserId(videoId, userId);

		if (videoUserEntry == null) {
			StringBundler msg = new StringBundler(6);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("videoId=");
			msg.append(videoId);

			msg.append(", userId=");
			msg.append(userId);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			if (_log.isWarnEnabled()) {
				_log.warn(msg.toString());
			}

			throw new NoSuchVideoUserEntryException(msg.toString());
		}

		return videoUserEntry;
	}

	/**
	 * Returns the video user entry where videoId = &#63; and userId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
	 *
	 * @param videoId the video ID
	 * @param userId the user ID
	 * @return the matching video user entry, or <code>null</code> if a matching video user entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoUserEntry fetchByVideoId_UserId(long videoId, long userId)
		throws SystemException {
		return fetchByVideoId_UserId(videoId, userId, true);
	}

	/**
	 * Returns the video user entry where videoId = &#63; and userId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
	 *
	 * @param videoId the video ID
	 * @param userId the user ID
	 * @param retrieveFromCache whether to use the finder cache
	 * @return the matching video user entry, or <code>null</code> if a matching video user entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoUserEntry fetchByVideoId_UserId(long videoId, long userId,
		boolean retrieveFromCache) throws SystemException {
		Object[] finderArgs = new Object[] { videoId, userId };

		Object result = null;

		if (retrieveFromCache) {
			result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_VIDEOID_USERID,
					finderArgs, this);
		}

		if (result == null) {
			StringBundler query = new StringBundler(4);

			query.append(_SQL_SELECT_VIDEOUSERENTRY_WHERE);

			query.append(_FINDER_COLUMN_VIDEOID_USERID_VIDEOID_2);

			query.append(_FINDER_COLUMN_VIDEOID_USERID_USERID_2);

			query.append(VideoUserEntryModelImpl.ORDER_BY_JPQL);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(videoId);

				qPos.add(userId);

				List<VideoUserEntry> list = q.list();

				result = list;

				VideoUserEntry videoUserEntry = null;

				if (list.isEmpty()) {
					FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIDEOID_USERID,
						finderArgs, list);
				}
				else {
					videoUserEntry = list.get(0);

					cacheResult(videoUserEntry);

					if ((videoUserEntry.getVideoId() != videoId) ||
							(videoUserEntry.getUserId() != userId)) {
						FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VIDEOID_USERID,
							finderArgs, videoUserEntry);
					}
				}

				return videoUserEntry;
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (result == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VIDEOID_USERID,
						finderArgs);
				}

				closeSession(session);
			}
		}
		else {
			if (result instanceof List<?>) {
				return null;
			}
			else {
				return (VideoUserEntry)result;
			}
		}
	}

	/**
	 * Returns all the video user entries where originCode = &#63; and serviceActive = &#63;.
	 *
	 * @param originCode the origin code
	 * @param serviceActive the service active
	 * @return the matching video user entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoUserEntry> findByOriginCode_ServiceActive(int originCode,
		int serviceActive) throws SystemException {
		return findByOriginCode_ServiceActive(originCode, serviceActive,
			QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the video user entries where originCode = &#63; and serviceActive = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param originCode the origin code
	 * @param serviceActive the service active
	 * @param start the lower bound of the range of video user entries
	 * @param end the upper bound of the range of video user entries (not inclusive)
	 * @return the range of matching video user entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoUserEntry> findByOriginCode_ServiceActive(int originCode,
		int serviceActive, int start, int end) throws SystemException {
		return findByOriginCode_ServiceActive(originCode, serviceActive, start,
			end, null);
	}

	/**
	 * Returns an ordered range of all the video user entries where originCode = &#63; and serviceActive = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param originCode the origin code
	 * @param serviceActive the service active
	 * @param start the lower bound of the range of video user entries
	 * @param end the upper bound of the range of video user entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of matching video user entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoUserEntry> findByOriginCode_ServiceActive(int originCode,
		int serviceActive, int start, int end,
		OrderByComparator orderByComparator) throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = null;

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORIGINCODE_SERVICEACTIVE;
			finderArgs = new Object[] { originCode, serviceActive };
		}
		else {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ORIGINCODE_SERVICEACTIVE;
			finderArgs = new Object[] {
					originCode, serviceActive,
					
					start, end, orderByComparator
				};
		}

		List<VideoUserEntry> list = (List<VideoUserEntry>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;

			if (orderByComparator != null) {
				query = new StringBundler(4 +
						(orderByComparator.getOrderByFields().length * 3));
			}
			else {
				query = new StringBundler(4);
			}

			query.append(_SQL_SELECT_VIDEOUSERENTRY_WHERE);

			query.append(_FINDER_COLUMN_ORIGINCODE_SERVICEACTIVE_ORIGINCODE_2);

			query.append(_FINDER_COLUMN_ORIGINCODE_SERVICEACTIVE_SERVICEACTIVE_2);

			if (orderByComparator != null) {
				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);
			}

			else {
				query.append(VideoUserEntryModelImpl.ORDER_BY_JPQL);
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(originCode);

				qPos.add(serviceActive);

				list = (List<VideoUserEntry>)QueryUtil.list(q, getDialect(),
						start, end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Returns the first video user entry in the ordered set where originCode = &#63; and serviceActive = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param originCode the origin code
	 * @param serviceActive the service active
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the first matching video user entry
	 * @throws vn.com.fis.portal.NoSuchVideoUserEntryException if a matching video user entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoUserEntry findByOriginCode_ServiceActive_First(int originCode,
		int serviceActive, OrderByComparator orderByComparator)
		throws NoSuchVideoUserEntryException, SystemException {
		List<VideoUserEntry> list = findByOriginCode_ServiceActive(originCode,
				serviceActive, 0, 1, orderByComparator);

		if (list.isEmpty()) {
			StringBundler msg = new StringBundler(6);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("originCode=");
			msg.append(originCode);

			msg.append(", serviceActive=");
			msg.append(serviceActive);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			throw new NoSuchVideoUserEntryException(msg.toString());
		}
		else {
			return list.get(0);
		}
	}

	/**
	 * Returns the last video user entry in the ordered set where originCode = &#63; and serviceActive = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param originCode the origin code
	 * @param serviceActive the service active
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the last matching video user entry
	 * @throws vn.com.fis.portal.NoSuchVideoUserEntryException if a matching video user entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoUserEntry findByOriginCode_ServiceActive_Last(int originCode,
		int serviceActive, OrderByComparator orderByComparator)
		throws NoSuchVideoUserEntryException, SystemException {
		int count = countByOriginCode_ServiceActive(originCode, serviceActive);

		List<VideoUserEntry> list = findByOriginCode_ServiceActive(originCode,
				serviceActive, count - 1, count, orderByComparator);

		if (list.isEmpty()) {
			StringBundler msg = new StringBundler(6);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("originCode=");
			msg.append(originCode);

			msg.append(", serviceActive=");
			msg.append(serviceActive);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			throw new NoSuchVideoUserEntryException(msg.toString());
		}
		else {
			return list.get(0);
		}
	}

	/**
	 * Returns the video user entries before and after the current video user entry in the ordered set where originCode = &#63; and serviceActive = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param videoUserId the primary key of the current video user entry
	 * @param originCode the origin code
	 * @param serviceActive the service active
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the previous, current, and next video user entry
	 * @throws vn.com.fis.portal.NoSuchVideoUserEntryException if a video user entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public VideoUserEntry[] findByOriginCode_ServiceActive_PrevAndNext(
		long videoUserId, int originCode, int serviceActive,
		OrderByComparator orderByComparator)
		throws NoSuchVideoUserEntryException, SystemException {
		VideoUserEntry videoUserEntry = findByPrimaryKey(videoUserId);

		Session session = null;

		try {
			session = openSession();

			VideoUserEntry[] array = new VideoUserEntryImpl[3];

			array[0] = getByOriginCode_ServiceActive_PrevAndNext(session,
					videoUserEntry, originCode, serviceActive,
					orderByComparator, true);

			array[1] = videoUserEntry;

			array[2] = getByOriginCode_ServiceActive_PrevAndNext(session,
					videoUserEntry, originCode, serviceActive,
					orderByComparator, false);

			return array;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	protected VideoUserEntry getByOriginCode_ServiceActive_PrevAndNext(
		Session session, VideoUserEntry videoUserEntry, int originCode,
		int serviceActive, OrderByComparator orderByComparator, boolean previous) {
		StringBundler query = null;

		if (orderByComparator != null) {
			query = new StringBundler(6 +
					(orderByComparator.getOrderByFields().length * 6));
		}
		else {
			query = new StringBundler(3);
		}

		query.append(_SQL_SELECT_VIDEOUSERENTRY_WHERE);

		query.append(_FINDER_COLUMN_ORIGINCODE_SERVICEACTIVE_ORIGINCODE_2);

		query.append(_FINDER_COLUMN_ORIGINCODE_SERVICEACTIVE_SERVICEACTIVE_2);

		if (orderByComparator != null) {
			String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

			if (orderByConditionFields.length > 0) {
				query.append(WHERE_AND);
			}

			for (int i = 0; i < orderByConditionFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByConditionFields[i]);

				if ((i + 1) < orderByConditionFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN_HAS_NEXT);
					}
					else {
						query.append(WHERE_LESSER_THAN_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN);
					}
					else {
						query.append(WHERE_LESSER_THAN);
					}
				}
			}

			query.append(ORDER_BY_CLAUSE);

			String[] orderByFields = orderByComparator.getOrderByFields();

			for (int i = 0; i < orderByFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByFields[i]);

				if ((i + 1) < orderByFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC_HAS_NEXT);
					}
					else {
						query.append(ORDER_BY_DESC_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC);
					}
					else {
						query.append(ORDER_BY_DESC);
					}
				}
			}
		}

		else {
			query.append(VideoUserEntryModelImpl.ORDER_BY_JPQL);
		}

		String sql = query.toString();

		Query q = session.createQuery(sql);

		q.setFirstResult(0);
		q.setMaxResults(2);

		QueryPos qPos = QueryPos.getInstance(q);

		qPos.add(originCode);

		qPos.add(serviceActive);

		if (orderByComparator != null) {
			Object[] values = orderByComparator.getOrderByConditionValues(videoUserEntry);

			for (Object value : values) {
				qPos.add(value);
			}
		}

		List<VideoUserEntry> list = q.list();

		if (list.size() == 2) {
			return list.get(1);
		}
		else {
			return null;
		}
	}

	/**
	 * Returns all the video user entries.
	 *
	 * @return the video user entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoUserEntry> findAll() throws SystemException {
		return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the video user entries.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of video user entries
	 * @param end the upper bound of the range of video user entries (not inclusive)
	 * @return the range of video user entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoUserEntry> findAll(int start, int end)
		throws SystemException {
		return findAll(start, end, null);
	}

	/**
	 * Returns an ordered range of all the video user entries.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of video user entries
	 * @param end the upper bound of the range of video user entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of video user entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<VideoUserEntry> findAll(int start, int end,
		OrderByComparator orderByComparator) throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = new Object[] { start, end, orderByComparator };

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
			finderArgs = FINDER_ARGS_EMPTY;
		}
		else {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
			finderArgs = new Object[] { start, end, orderByComparator };
		}

		List<VideoUserEntry> list = (List<VideoUserEntry>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;
			String sql = null;

			if (orderByComparator != null) {
				query = new StringBundler(2 +
						(orderByComparator.getOrderByFields().length * 3));

				query.append(_SQL_SELECT_VIDEOUSERENTRY);

				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);

				sql = query.toString();
			}
			else {
				sql = _SQL_SELECT_VIDEOUSERENTRY.concat(VideoUserEntryModelImpl.ORDER_BY_JPQL);
			}

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				if (orderByComparator == null) {
					list = (List<VideoUserEntry>)QueryUtil.list(q,
							getDialect(), start, end, false);

					Collections.sort(list);
				}
				else {
					list = (List<VideoUserEntry>)QueryUtil.list(q,
							getDialect(), start, end);
				}
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Removes all the video user entries where userId = &#63; and originCode = &#63; from the database.
	 *
	 * @param userId the user ID
	 * @param originCode the origin code
	 * @throws SystemException if a system exception occurred
	 */
	public void removeByUser_OriginCode(long userId, int originCode)
		throws SystemException {
		for (VideoUserEntry videoUserEntry : findByUser_OriginCode(userId,
				originCode)) {
			remove(videoUserEntry);
		}
	}

	/**
	 * Removes all the video user entries where userId = &#63; and serviceActive = &#63; from the database.
	 *
	 * @param userId the user ID
	 * @param serviceActive the service active
	 * @throws SystemException if a system exception occurred
	 */
	public void removeByUser_ServiceActive(long userId, int serviceActive)
		throws SystemException {
		for (VideoUserEntry videoUserEntry : findByUser_ServiceActive(userId,
				serviceActive)) {
			remove(videoUserEntry);
		}
	}

	/**
	 * Removes the video user entry where videoId = &#63; and userId = &#63; from the database.
	 *
	 * @param videoId the video ID
	 * @param userId the user ID
	 * @throws SystemException if a system exception occurred
	 */
	public void removeByVideoId_UserId(long videoId, long userId)
		throws NoSuchVideoUserEntryException, SystemException {
		VideoUserEntry videoUserEntry = findByVideoId_UserId(videoId, userId);

		remove(videoUserEntry);
	}

	/**
	 * Removes all the video user entries where originCode = &#63; and serviceActive = &#63; from the database.
	 *
	 * @param originCode the origin code
	 * @param serviceActive the service active
	 * @throws SystemException if a system exception occurred
	 */
	public void removeByOriginCode_ServiceActive(int originCode,
		int serviceActive) throws SystemException {
		for (VideoUserEntry videoUserEntry : findByOriginCode_ServiceActive(
				originCode, serviceActive)) {
			remove(videoUserEntry);
		}
	}

	/**
	 * Removes all the video user entries from the database.
	 *
	 * @throws SystemException if a system exception occurred
	 */
	public void removeAll() throws SystemException {
		for (VideoUserEntry videoUserEntry : findAll()) {
			remove(videoUserEntry);
		}
	}

	/**
	 * Returns the number of video user entries where userId = &#63; and originCode = &#63;.
	 *
	 * @param userId the user ID
	 * @param originCode the origin code
	 * @return the number of matching video user entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countByUser_OriginCode(long userId, int originCode)
		throws SystemException {
		Object[] finderArgs = new Object[] { userId, originCode };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USER_ORIGINCODE,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(3);

			query.append(_SQL_COUNT_VIDEOUSERENTRY_WHERE);

			query.append(_FINDER_COLUMN_USER_ORIGINCODE_USERID_2);

			query.append(_FINDER_COLUMN_USER_ORIGINCODE_ORIGINCODE_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(userId);

				qPos.add(originCode);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USER_ORIGINCODE,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of video user entries where userId = &#63; and serviceActive = &#63;.
	 *
	 * @param userId the user ID
	 * @param serviceActive the service active
	 * @return the number of matching video user entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countByUser_ServiceActive(long userId, int serviceActive)
		throws SystemException {
		Object[] finderArgs = new Object[] { userId, serviceActive };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USER_SERVICEACTIVE,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(3);

			query.append(_SQL_COUNT_VIDEOUSERENTRY_WHERE);

			query.append(_FINDER_COLUMN_USER_SERVICEACTIVE_USERID_2);

			query.append(_FINDER_COLUMN_USER_SERVICEACTIVE_SERVICEACTIVE_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(userId);

				qPos.add(serviceActive);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USER_SERVICEACTIVE,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of video user entries where videoId = &#63; and userId = &#63;.
	 *
	 * @param videoId the video ID
	 * @param userId the user ID
	 * @return the number of matching video user entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countByVideoId_UserId(long videoId, long userId)
		throws SystemException {
		Object[] finderArgs = new Object[] { videoId, userId };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_VIDEOID_USERID,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(3);

			query.append(_SQL_COUNT_VIDEOUSERENTRY_WHERE);

			query.append(_FINDER_COLUMN_VIDEOID_USERID_VIDEOID_2);

			query.append(_FINDER_COLUMN_VIDEOID_USERID_USERID_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(videoId);

				qPos.add(userId);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_VIDEOID_USERID,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of video user entries where originCode = &#63; and serviceActive = &#63;.
	 *
	 * @param originCode the origin code
	 * @param serviceActive the service active
	 * @return the number of matching video user entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countByOriginCode_ServiceActive(int originCode, int serviceActive)
		throws SystemException {
		Object[] finderArgs = new Object[] { originCode, serviceActive };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ORIGINCODE_SERVICEACTIVE,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(3);

			query.append(_SQL_COUNT_VIDEOUSERENTRY_WHERE);

			query.append(_FINDER_COLUMN_ORIGINCODE_SERVICEACTIVE_ORIGINCODE_2);

			query.append(_FINDER_COLUMN_ORIGINCODE_SERVICEACTIVE_SERVICEACTIVE_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(originCode);

				qPos.add(serviceActive);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ORIGINCODE_SERVICEACTIVE,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of video user entries.
	 *
	 * @return the number of video user entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countAll() throws SystemException {
		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
				FINDER_ARGS_EMPTY, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(_SQL_COUNT_VIDEOUSERENTRY);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
					FINDER_ARGS_EMPTY, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Initializes the video user entry persistence.
	 */
	public void afterPropertiesSet() {
		String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
					com.liferay.util.service.ServiceProps.get(
						"value.object.listener.vn.com.fis.portal.model.VideoUserEntry")));

		if (listenerClassNames.length > 0) {
			try {
				List<ModelListener<VideoUserEntry>> listenersList = new ArrayList<ModelListener<VideoUserEntry>>();

				for (String listenerClassName : listenerClassNames) {
					listenersList.add((ModelListener<VideoUserEntry>)InstanceFactory.newInstance(
							listenerClassName));
				}

				listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
			}
			catch (Exception e) {
				_log.error(e);
			}
		}
	}

	public void destroy() {
		EntityCacheUtil.removeCache(VideoUserEntryImpl.class.getName());
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	@BeanReference(type = CategoryEntryPersistence.class)
	protected CategoryEntryPersistence categoryEntryPersistence;
	@BeanReference(type = CategoryVideoEntryPersistence.class)
	protected CategoryVideoEntryPersistence categoryVideoEntryPersistence;
	@BeanReference(type = UserEntryPersistence.class)
	protected UserEntryPersistence userEntryPersistence;
	@BeanReference(type = VideoEntryPersistence.class)
	protected VideoEntryPersistence videoEntryPersistence;
	@BeanReference(type = VideoUserEntryPersistence.class)
	protected VideoUserEntryPersistence videoUserEntryPersistence;
	@BeanReference(type = ResourcePersistence.class)
	protected ResourcePersistence resourcePersistence;
	@BeanReference(type = UserPersistence.class)
	protected UserPersistence userPersistence;
	private static final String _SQL_SELECT_VIDEOUSERENTRY = "SELECT videoUserEntry FROM VideoUserEntry videoUserEntry";
	private static final String _SQL_SELECT_VIDEOUSERENTRY_WHERE = "SELECT videoUserEntry FROM VideoUserEntry videoUserEntry WHERE ";
	private static final String _SQL_COUNT_VIDEOUSERENTRY = "SELECT COUNT(videoUserEntry) FROM VideoUserEntry videoUserEntry";
	private static final String _SQL_COUNT_VIDEOUSERENTRY_WHERE = "SELECT COUNT(videoUserEntry) FROM VideoUserEntry videoUserEntry WHERE ";
	private static final String _FINDER_COLUMN_USER_ORIGINCODE_USERID_2 = "videoUserEntry.userId = ? AND ";
	private static final String _FINDER_COLUMN_USER_ORIGINCODE_ORIGINCODE_2 = "videoUserEntry.originCode = ?";
	private static final String _FINDER_COLUMN_USER_SERVICEACTIVE_USERID_2 = "videoUserEntry.userId = ? AND ";
	private static final String _FINDER_COLUMN_USER_SERVICEACTIVE_SERVICEACTIVE_2 =
		"videoUserEntry.serviceActive = ?";
	private static final String _FINDER_COLUMN_VIDEOID_USERID_VIDEOID_2 = "videoUserEntry.videoId = ? AND ";
	private static final String _FINDER_COLUMN_VIDEOID_USERID_USERID_2 = "videoUserEntry.userId = ?";
	private static final String _FINDER_COLUMN_ORIGINCODE_SERVICEACTIVE_ORIGINCODE_2 =
		"videoUserEntry.originCode = ? AND ";
	private static final String _FINDER_COLUMN_ORIGINCODE_SERVICEACTIVE_SERVICEACTIVE_2 =
		"videoUserEntry.serviceActive = ?";
	private static final String _ORDER_BY_ENTITY_ALIAS = "videoUserEntry.";
	private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No VideoUserEntry exists with the primary key ";
	private static final String _NO_SUCH_ENTITY_WITH_KEY = "No VideoUserEntry exists with the key {";
	private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = GetterUtil.getBoolean(PropsUtil.get(
				PropsKeys.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE));
	private static Log _log = LogFactoryUtil.getLog(VideoUserEntryPersistenceImpl.class);
	private static VideoUserEntry _nullVideoUserEntry = new VideoUserEntryImpl() {
			@Override
			public Object clone() {
				return this;
			}

			@Override
			public CacheModel<VideoUserEntry> toCacheModel() {
				return _nullVideoUserEntryCacheModel;
			}
		};

	private static CacheModel<VideoUserEntry> _nullVideoUserEntryCacheModel = new CacheModel<VideoUserEntry>() {
			public VideoUserEntry toEntityModel() {
				return _nullVideoUserEntry;
			}
		};
}